<?php
/**
 * @category 	MemberDao.php
 * @author 		Sung Hoon, Cho (akdddnet@gmail.com)
 * @since		2011. 5. 2.
 * @license		BSD License
 * @version		0.1
 */
 
global $CFG;
require_once $CFG->FW_DIR."/mvc/Dao.php";
 
class MemberDao extends Dao {
	
 	function __construct(array $db_type = null) {
 		parent::__construct($db_type);	
 	}
 	
 	
 	
	function doLogin(DTO $dto) {
 		$query = "
 			SELECT 
 					*
 			FROM	member
 			WHERE	1 = 1
 			AND		m_id = :m_id
 			AND		m_password = password(:m_pwd) 
 		";
 		
 		$bind = array(
 				 ":m_id"=>$dto->eb->m_id
 				,":m_pwd"=>$dto->eb->m_password
 		);
 		
 		return $this->db->query($query, $bind)->fetchAll();
 	}
 	
 	
 	function index(DTO $dto) {
 		$query = "
 				SELECT 
 							*
 				FROM 		member
 				WHERE		1 = 1
 		";

 		$dto->list = $this->db->query($query)->fetchAll();
 		
 		return $dto;
 	}
 	
 	
 	
 	
 	
 	
 	
	function view(DTO $dto) {
 		$query ="
 				SELECT		*
 				FROM 		member
 				WHERE		1 = 1
 				AND			m_seq = :m_seq
 		";
 		
 		$bind = array(
 				"m_seq"=>$dto->eb->m_seq
 		);
 		
 		$dto->obj = $this->db->query($query, $bind)->fetch();
 		
 		return $dto;
 	}
 	
 	
	function doAdd(DTO $dto) {
 		$query = "
 				INSERT INTO member
 					(m_id, m_password, m_name, m_email, m_sendemail, m_auth, m_sign, m_cdate)
 				VALUES
 					(:m_id, password(:m_password), :m_name, :m_email, :m_sendemail, :m_auth, :m_sign, now())
 		";
 		
 		$bind = array(
 				 "m_id"=>$dto->eb->m_id
 				,"m_password"=>$dto->eb->m_password
 				,"m_name"=>$dto->eb->m_name
 				,"m_email"=>$dto->eb->m_email
 				,"m_sendemail"=>$dto->eb->m_sendemail
 				,"m_auth"=>$dto->eb->m_auth
 				,"m_sign"=>$dto->eb->m_sign
 		);
 		
 		$dto->rc = $this->db->query($query, $bind)->rowCount();
 		
 		return $dto;
 	}
 	
 	
 	
	function doUpdate(DTO $dto) {
 		$query = "
 				UPDATE member SET
	 					 m_name 		= :m_name
	 					,m_email 		= :m_email
	 					,m_sendemail	= :m_sendemail
	 					,m_auth			= :m_auth
	 					,m_sign			= :m_sign
	 					,m_mdate		= now()
 				WHERE	1 = 1
 				AND		m_seq 			= :m_seq
 						
 		";
 		
 		$bind = array(
 				 "m_seq"=>$dto->eb->m_seq
 				,"m_name"=>$dto->eb->m_name
 				,"m_email"=>$dto->eb->m_email
 				,"m_sendemail"=>$dto->eb->m_sendemail
 				,"m_auth"=>$dto->eb->m_auth
 				,"m_sign"=>$dto->eb->m_sign
 		);
 		
 		$dto->rc = $this->db->query($query, $bind)->rowCount();
 		
 		return $dto;
 	}
 	
 	
 	function doDelete(DTO $dto) {
 		$query = "
 				DELETE FROM member
 				WHERE	1 = 1
 				AND		m_seq = :m_seq
 				AND		m_delete != 0 
 		";
 		
 		$bind = array("m_seq"=>$dto->eb->m_seq);
 		
 		$dto->rc = $this->db->query($query, $bind)->rowCount();
 		
 		return $dto;
 	}
 	
 	function doAuth(DTO $dto) {
 		$query = "
 				UPDATE 	member SET
 						m_auth = :m_auth
 				WHERE	1 = 1
 				AND		m_seq = :m_seq
 		";
 		
 		$bind = array(
 				 "m_auth"=>$dto->eb->m_auth
 				,"m_seq"=>$dto->eb->m_seq
 		);
 		
 		$dto->rc = $this->db->query($query, $bind)->rowCount();
 		
 		return $dto;
 	}
 	
 	function getPasswordCheck(DTO $dto) {
 		$query = "
 				SELECT 
 						COUNT(*) 
 				FROM	member
 				WHERE	1 = 1
 				AND		m_seq = :m_seq
 				AND		m_password = password(:m_password)
 		";
 		
 		$bind = array(
 				 "m_seq"=>$dto->eb->m_seq
 				,"m_password"=>$dto->eb->m_password
 		);
 		
 		$dto->rc = $this->db->query($query, $bind)->field();
 		
 		return $dto;
 	}
 	
 	function doPasswordChange(DTO $dto) {
 		$query = "
 				UPDATE 	member SET
 						m_password = password(:m_password)
 				WHERE	1 = 1
 				AND		m_seq = :m_seq
 		";
 		
 		$bind = array(
 				 "m_password"=>$dto->eb->m_password
 				,"m_seq"=>$dto->eb->m_seq
 		);
 		
 		$dto->rc = $this->db->query($query, $bind)->rowCount();
 		
 		return $dto;
 	}
 	
}